<script src="{{ getAssets }}js/amazeui.datatables.min.js?v={{ assets_version }}"></script>
<script>
	var tables = $('#dataTables').DataTable({
		"sAjaxSource" : '{{ urlfor "RetailController.RefundQuery"}}'
		,"bLengthChange": false
		,"fnServerData" : function(sSource, aoData, fnCallback) {
			var queryParams = checkQueryTableData(aoData);
            var form = $('#search-form').serializeArray();
            $.each(form, function(i, value){
                queryParams[value.name] = value.value;
            });
			$.post(sSource, JSON.stringify(queryParams),function(resp) {
				fnCallback(resp);
			},'json')
		}
		,columns: [
            {"bSortable": false, render:function(data, type, full, meta) {
                    return full.ManualNumber;
                }}
            ,{"bSortable": false, render:function(data, type, full, meta) {
                    return '<a href="javascript:;" data-retid="'+ full.RetailsId +'" onclick="popWindRetailsView(this);return false">'+ full.RetailsManualNumber+ '</a>';
                }}
            ,{"bSortable": false, render:function(data, type, full, meta) {
                    return full.Archives.Realname;
            }}
            ,{"bSortable": false, render:function(data, type, full, meta) {
                    return full.Archives.Mobile;
            }}
            ,{"bSortable": false, render:function(data, type, full, meta) {
                    return full.BusinessName;
            }}
            ,{"bSortable": false, render:function(data, type, full, meta) {
                    return timetrans(full.CreatedAt);
                }}
            ,{"bSortable": false, render:function(data, type, full, meta) {
                    return full.TotalMoney;
            }}
            ,{"bSortable": false, render:function(data, type, full, meta) {
                    return timetrans(full.CreatedAt);
                }}
            ,{"bSortable": false, render:function(data, type, full, meta) {
                    return full.SumPayable;
            }}
			,{
				"mDataProp": "Action", 
				"bSortable": false, 
				"sWidth":"6%",
				"render": function ( data, type, full, meta ) {
                    var d = [];
                    d.push('<a href="javascript:;" data-retid="'+ full.Id +'" onclick="return popWindView(this);">退货清单</a>');
                    return d.join('');
				}  
			 } 
		]
		,"aLengthMenu":[20, 50, 100, 200]
		,'bLengthChange': true
		,"serverSide": true
		,"bPaginate" : true
		,"bFilter" : false	//是否启动过滤、搜索功能 
		,"bInfo" : true //是否显示页脚信息，DataTables插件左下角显示记录数
		,"bProcessing" : true //DataTables载入数据时，是否显示‘进度’提示  
		  
	});
	$('#query-submit').click(function(){
        $("#dataTables").dataTable().fnDraw(false);

    });
	function reloadTable() {
		$("#dataTables").dataTable().fnDraw(false);
	}

	function dialogReback() {
		reloadTable();
	}
	
	$('#refresh').click(function(){
		reloadTable();
		return false;
	});
    function popWindView(obj) {
	    var o = $(obj);
        var sales_id = o.data('retid');
        layer.open({
            type: 2
            , title: '退货清单'
            , shadeClose: true
            , shade: 0.2
            , id: 'search_retail_view_dialog'
            , area: ['90%', "80%"]
            , content: ['{{ urlfor "RetailController.RefundView" }}' + '?sales_id='+ sales_id]
            , anim: 1 //动画类型
            ,cancel: function(index, layero){
                layer.close(index);
                return false;
            }
        });
    }
    function popWindRetailsView(obj) {
        var o = $(obj);
        var sales_id = o.data('retid');
        layer.open({
            type: 2
            , title: '单据详情'
            , shadeClose: true
            , shade: 0.2
            , id: 'search_retail_view_dialog'
            , area: ['100%', "100%"]
            , content: ['{{ urlfor "RetailController.View" }}' + '?sales_id='+ sales_id]
            , anim: 1 //动画类型
            ,cancel: function(index, layero){
                layer.close(index);
                return false;
            }
        });
    }
</script>